
import java.util.Scanner;
 // 事件推送
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input_1 = scanner.nextInt();
        int input_2 = scanner.nextInt();
        int index = scanner.nextInt();
        int[] arr1 = new int[input_1];
        int[] arr2 = new int[input_2];

        for (int i = 0; i < input_1; i++) {
            arr1[i] = scanner.nextInt();
        }

        for (int i = 0; i < input_2; i++) {
            arr2[i] = scanner.nextInt();
        }
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr2.length; j++) {
                if (arr1[i] <= arr2[j] && arr2[j] - arr1[i] <= index)
                {
                    System.out.println(arr1[i] + ' ' + arr2[j]);
                    break;
                }

            }

        }
        scanner.close();
    }

}

